<?php

namespace App\Admin\Controllers;

use App\Models\Business;
use App\Models\BusinessType;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class BusinessController extends AdminController
{
    protected $title='商家资源';
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make( Business::with('type'), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('title');
            $grid->column('logo')->image('',100,100);
            $grid->column('type.name','类型');
            $grid->column('chanpin');
            $grid->column('city');
            $grid->column('price');

            $grid->column('xiaofei');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->like('title');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Business(), function (Show $show) {
            $show->field('id');
            $show->field('bussine_type_id');
            $show->field('chanpin');
            $show->field('city');
            $show->field('logo');
            $show->field('price');
            $show->field('title');
            $show->field('xiaofei');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Business(), function (Form $form) {
            $form->text('title')->required();
            $form->select('bussine_type_id')
                ->options(BusinessType::all()->pluck('name','id'))

            ;
            $form->text('chanpin')->required();
            $form->text('city')->required();
            $form->image('logo')->autoUpload()->chunkSize(1024)->required();
            $form->text('price')->required();
            $form->text('xiaofei')->required();
        });
    }
}
